#ifndef EMS_CORE_APPLICATION_H
#define EMS_CORE_APPLICATION_H

#include <memory>
#include <string>

namespace ems {

namespace device {
    class DeviceManager;
}

namespace service {
    class DataCollector;
    class DataUploader;
    class AlarmManager;
    class DispatchService;
}

namespace web {
    class WebServer;
}

namespace core {

class Application {
public:
    static Application& getInstance();
    
    bool initialize(const std::string& configPath);
    void run();
    void shutdown();
    void requestShutdown();
    
    bool isRunning() const { return running_; }

private:
    Application() = default;
    ~Application() = default;
    Application(const Application&) = delete;
    Application& operator=(const Application&) = delete;
    
    void loadConfiguration(const std::string& configPath);
    void initializeModules();
    void startServices();
    void stopServices();
    void cleanupWebProcesses();
    
    bool running_;
    std::string configPath_;
    
    std::unique_ptr<device::DeviceManager> deviceManager_;
    std::unique_ptr<service::DataCollector> dataCollector_;
    std::unique_ptr<service::DataUploader> dataUploader_;
    std::unique_ptr<service::AlarmManager> alarmManager_;
    std::unique_ptr<service::DispatchService> dispatchService_;
    std::unique_ptr<web::WebServer> webServer_;
};

}  // namespace core
}  // namespace ems

#endif  // EMS_CORE_APPLICATION_H
